/**
 * 浅度copy,截断原型链
 * @param target
 */
export function deepCopy(target) {
    return JSON.parse(JSON.stringify(target || {}))
}

/**
 * 数组去重复
 * @param array
 * @returns {Array}
 */
export function uniqueArray(array) {
    return Array.from(new Set(array))
}

/**
 * 断言函数，阻断执行
 * @param 判断条件
 * @param 错误提示
 */
export function assert(condition, msg) {
    if (!condition) throw new Error(`${msg}`);
}

/**
 * 部分描述获取
 * @param obj [Object] loadCompService
 * @param key [String]  loadCompService Map key
 * @param part [String] loadCompService Map part key
 * @param desc_key [String]  `namespace.biz_name`
 * @param part_name [String] page name/ widget name /module name
 * @returns {*}
 */
export function findPartDesc(obj, key, part, desc_key, part_name) {
    const _desc = obj[key] && obj[key][desc_key] && obj[key][desc_key][part]
    return _desc && _desc[part_name]
}

/**
 * 拷贝属性
 * @param target [Object[Object]]
 * @param properties [Array[String]] 需要拷贝的属性
 * @returns {{}}
 */
export function copyProperty(target, properties) {
    const map = {}
    Object.keys(target || {}).forEach(id => {
        map[id] = {}
        properties.forEach(key => {
            map[key] = target[id][key]
        })
    })
    return map
}

